<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="misc.Configurations,data.UploadLog,data.File,controller.ManageController"%>
<%@page import="java.util.LinkedList, java.text.SimpleDateFormat"%>
<%@page import="data.AuthorizationSession"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title><%=Configurations.title%>Management</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<h1>Management</h1>
<h2><%= new java.util.Date() %></h2>
<%
if(AuthorizationSession.checkAuthorizationToken(request,response,true))
{
%>
    <b>Welcome, <%= session.getAttribute("name") %>!</b>
    <%
}
%>
<h2>Actions</h2>
<a href="Admin.jsp">Admin (Secret)</a><br/>
<a href="Upload.jsp">Upload a new file</a><br/>
<a href="DownloadForm.jsp">Download a file</a><br/>
<a href="Logout.jsp">Log out</a><br/>
<br/>
<hr/>
<h2>List of files</h2>
    <table class="display">
        <tr class="heading">
          <td>File name</td>
          <td>File size</td>
          <td>File type</td>
          <td>IP address</td>
          <td>Start date</td>
          <td>Finished date</td>
          <td>Start time</td>
          <td>Finished time</td>
          <td>Password protected</td>
          <td>Actions</td>
        </tr>
        
        <%
        ManageController controlManage = new ManageController();
        LinkedList<UploadLog> manage = controlManage.retrieveUploadLog((String)session.getAttribute("name"));
        for(int i=0;i<manage.size();i++){
            UploadLog this_manage = manage.get(i);
            File manage_file = controlManage.retrieveFile(this_manage.getFileID());
        %>
        <tr class="row">
          <td><%=this_manage.getFileName() %></td>
          <td><%=File.convertToMB(this_manage.getFilesize()) %></td>
          <td><%=this_manage.getFiletype() %></td>
          <td><%=this_manage.getIPaddress() %></td>
          <td><%=new SimpleDateFormat("dd MMMMM yyyy").format(this_manage.getStart()).toString() %></td>
          <td><%=new SimpleDateFormat("dd MMMMM yyyy").format(this_manage.getFinish()).toString() %></td>
          <td><%=new SimpleDateFormat("h:mm:ss a z").format(this_manage.getStart()).toString() %></td>
          <td><%=new SimpleDateFormat("h:mm:ss a z").format(this_manage.getFinish()).toString() %></td>
          <td><%=File.protectedFile(this_manage.isFileIsProtected()) %></td>
          <td>
            <a href="LogView.jsp?file=<%=manage_file.getHashedCode() %>" target="_blank">View logs</a>
            <a href="Delete.jsp?file=<%=manage_file.getHashedCode()%>" target="_parent">Delete</a>
            <%
            if(!this_manage.isFileIsProtected())
            {
            %>
            <a href="PasswordProtect.jsp?file=<%=manage_file.getHashedCode()%>" target="_parent">Add password</a>
            <%}%>
            <a href="Download.jsp?file=<%=manage_file.getHashedCode() %>" target="_blank">Download</a>
          </td>
        </tr>
        <%}%>
    </table>
</body>
</html>